import { useState } from "react"
import { useNavigate } from "react-router-dom"
import  {lognin} from "../../api/index"
function Login(){
    const [name,setName]=useState("")
    const [password,setPassword]=useState("")
    const  navigate = useNavigate()
    const log = async ()=>{
        if(name&&password){
           let res  =  await lognin({
            password:password,
            userName:name
           })
           if (res.data.code === 0){
            navigate('/')
           }else{
            alert(res.data.msg)
           }
           
        }
    }
    return(
        <div>
            <input type="text" value={name} onChange={(e)=>setName(e.target.value)} placeholder="用户名" />
            <input type="text"  value={password} onChange={(e)=>setPassword(e.target.value)} placeholder="密码" />
           <button onClick={log}>登录</button>
        </div>
    )
}

export default Login